#include "..\\GameEngine\\GameEngine.h"
#include "Player.h"
#include "SpaceBack.h"
#include "Bot.h"
#include <memory>

class SinglePlayer : public GameState, public IListener<ClickEventArgs>
{       
    Button* btnBack;
    Player* m_plr;
    CBot *m_bot;
        
public:
    virtual void IListener<ClickEventArgs>::operator ()(TGameObject* sender, ClickEventArgs* args)
    {
        GameState::Switch("MainMenu");
    }

    virtual void Initialize() 
    {           
        GameEngine::SetBackground(new SpaceBack());
        
        btnBack = new Button("Back",300,480-30);        
        btnBack->SetListener(this);
        
        m_plr = new Player("Ship1", 0, 0);
        WORD x = 300, y = 300;
        m_plr->Respawn(x, y);
        
        m_bot = new CBot(m_plr, "Ship2", 0, 0);        
        x = 100, y = 100;
        m_bot->Respawn(x, y);
                
        GameEngine::AddObject(m_plr);        
        GameEngine::AddObject(m_bot);  
        GameEngine::AddObject(btnBack);
    }

    virtual void Deinitialize() 
    {        
        
    }

    virtual void DoAction() 
    {
        DWORD t = timeGetTime();
                
        if (dbLeftKey()) 
        {
            m_plr->Turn(-5);
        }else if (dbRightKey()) 
        {
            m_plr->Turn(+5);
        }else{
            m_plr->Turn(0);
        }

        if (dbUpKey()) 
        {            
            m_plr->Move(8);

        }
        else if (dbDownKey())
        {
            m_plr->Move(-4);
        }
        else
        {
            m_plr->Move(0);
        }
        
        if (dbSpaceKey())
        {
            m_plr->Fire();
        }             
    }

    virtual void OnDraw() 
    {
        
    }
};

